package com.ruoyi.tester.executor;

import com.ruoyi.tester.domain.TaskInterfaceEffectiveInfo;
import com.ruoyi.tester.executor.thread.InvolutedThreadPool;

import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

/**
 * @author SongJun
 * @description 接口执行器工具
 * @date 2022/4/15 15:45
 */
public class InterfaceExecutorUtil {
    private static int corePoolSize = Runtime.getRuntime().availableProcessors();
    private static int maximumPoolSize = corePoolSize * 4;
    private static long keepAliveTime = 1800;
    private static TimeUnit unit = TimeUnit.SECONDS;
    private static BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(512);
//    private static ThreadPoolExecutor pool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
    private static InvolutedThreadPool pool = new InvolutedThreadPool(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, 256);
    static {
        pool.allowCoreThreadTimeOut(true);
    }

    public static void callInterface(TaskInterfaceEffectiveInfo interfaceInfo, IExtraHandler extraHandler, List<TaskInterfaceEffectiveInfo> effectiveList, Map<Long, String> calledStatus){
        pool.submit(new InterfaceCallable(interfaceInfo, extraHandler, effectiveList, calledStatus));
    }
}
